﻿$(function () {
    $("#status").ligerComboBox({
        width: 120,
        cancelable: false,
        valueFieldID: 'hdnStatus',
        value: -1
    });

    $('#btnSearch').click(function () {
        search();
    });

    $("#btnAdd").click(function () {
        location.href = "/Personnel/EditNurseTransfer/Index";
    });

    search();
});

//加载列表
function initTable(queryData, pageNumber) {
    $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Personnel/NurseTransferList/Search?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: -5,
        columns: [
        { display: '申请时间', name: 'CreateTime' },
        { display: '工号', name: 'UserId' },
        { display: '姓名', name: 'UserName' },
        { display: '性别', name: 'sex' },
        { display: '职称', name: 'PositionTitle' },
        { display: '所在病区', name: 'DepartmentName' },
        { display: '转科病区', name: 'InDepartmentName' },
        {
            display: '审核状态', name: '', render: function (row) {
                var html = '';
                if (row.Status == 0) {
                    html = '未审核';
                }
                else if (row.Status == 1) {
                    html = '已审核';
                }
                else {
                    html = '已驳回';
                }
                return html;
            }
        },
        {
            display: '操作', name: '', minWidth: 100, render: function (row) {
                return '<a href="javascript:void(0);"  class="a-edit" onclick="edit(' + row.id + ',' + row.Status + ')">查看</a>';
            }
        }],
        onSuccess: function (data) {
            var flag = true;
            var rows = data.Rows;
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].Status != 1) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                $("#btnAdd").show();
            }
            else {
                $("#btnAdd").hide();
            }
        }
    });
    GridNoData($("#maingrid"));
}

//搜索
function search(pageNumber) {
    var queryData = {
        status: $("#hdnStatus").val()
    }
    initTable(queryData, pageNumber);
}

//审核/编辑/查看
function edit(id, status) {
    window.location.href = "/Personnel/EditNurseTransfer/Index?id=" + id + "&status=" + status;
}